﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using Distrackting.BusinessLayer;
using Distrackting.DataLayer;

namespace Distrackting.Parser
{
    public class Exportador
    {
        public static String exportarFicheiroGPS(Guid cod_perc, String filepath)
        {
            try
            {
                Gpx gpx = new Gpx();
                Track trk = new Track();
                Percurso p = GerirPercursos.getPercurso(cod_perc);
                //String nomefich = ("C:\\Documents and Settings\\Nuno\\Os meus documentos\\Nuno\\Universidade\\"+ p.nome + ".gpx");
                String nomefich = (filepath + p.nome + ".gpx");

                foreach (Ponto pt in p.Pontos.ToList<Ponto>())
                {
                    Waypoint wp = new Waypoint(pt.lat, pt.lng);
                    wp.setEle(pt.alt);
                    wp.setTime(pt.hora.ToString());
                    trk.addWpt(wp);
                }
                gpx.addTrack(trk);
                gpx.printGpx(nomefich,p.nome);
                return nomefich;
                
            }
            catch(Exception e)
            {
                throw e;
            }
            
        }
    }
}
